# metallb 安装
# 读取输入
read -p "输入宿主机同网段IP池范围 如: 192.168.140.64/26 > " addressPool
echo "IP池范围是：$addressPool"
read -p "确认:Please input (Y/N) : " yn

#1 创建metallb 的namespace.yaml
cat <<EOF > ./namespace.yaml 
apiVersion: v1
kind: Namespace
metadata:
  name: metallb-system
  labels:
    app: metallb
EOF


# 创建metallb 的layer2模式的网络配置
cat <<EOF > ./metallb-layer2-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - $addressPool
EOF



# 安装namespace
kubectl apply -f ./namespace.yaml

# http://t.bzy.skieer.com 这个是我们测试网站。暂时把 http://t.bzy.skieer.com/res/metallb.yaml下载下来放上去了
kubectl apply -f http://t.bzy.skieer.com/res/metallb.yml

# On first install only
kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"

#安装网络配置
kubectl apply -f ./metallb-layer2-configmap.yaml